package com.eedi.framework.permission.dal.mapper;

import com.eedi.framework.mybatis.core.mapper.BaseMapperX;
import com.eedi.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.eedi.framework.permission.dal.dataobject.OrgMenuDO;
import com.eedi.framework.permission.controller.org.vo.menu.OrgMenuListReq;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface OrgMenuMapper extends BaseMapperX<OrgMenuDO> {

    default OrgMenuDO selectByParentIdAndName(String parentId, String name) {
        return selectOne(OrgMenuDO::getParentOrgMenuId, parentId, OrgMenuDO::getOrgMenuName, name);
    }

    default Long selectCountByParentId(String parentId) {
        return selectCount(OrgMenuDO::getParentOrgMenuId, parentId);
    }

    default List<OrgMenuDO> selectList(OrgMenuListReq reqVO) {
        return selectList(new LambdaQueryWrapperX<OrgMenuDO>()
                .likeIfPresent(OrgMenuDO::getOrgMenuName, reqVO.getOrgMenuName())
                .eqIfPresent(OrgMenuDO::getOrgMenuStatus, reqVO.getOrgRoleStatus()));
    }

    default List<OrgMenuDO> selectListByPermission(String permission) {
        return selectList(OrgMenuDO::getOrgMenuPermission, permission);
    }
}
